﻿using System;
using System.Data.SqlTypes;
using BMServiceGenerator.Tests.InvoicesService;
using NUnit.Framework;

namespace BMServiceGenerator.Tests
{
    /// <summary>
    /// Note that this is a integration test. It requires a deployed service with namespace Test.Test and the test activity within the project to be deployed.
    /// </summary>
    [TestFixture]
    public class InvoicesActivityTests
    {
        [Test]
        public void LogCompleteInvoicesServiceTest()
        {
            var srv = new InvoicesServiceClient();
            var activityId = Guid.NewGuid().ToString();
            srv.LogCompleteActivity(activityId, new InvoicesServiceType() { InvoiceId = "1001", Amount = 1, ReceivedDate = DateTime.Now });
        }

        [Test]
        public void UpdatedInvoicesServiceTest()
        {
            var srv = new InvoicesServiceClient();
            var activityId = Guid.NewGuid().ToString();
            srv.BeginActivity(activityId);
            srv.UpdateActivity(activityId, new InvoicesServiceType() { InvoiceId = "1001", ReceivedDate = DateTime.Now, Amount = 1001 });
            srv.EndActivity(activityId);
        }

        [Test]
        public void ContinuatedInvoicesServiceTest()
        {
            var invoiceId = string.Concat("InvoiceId#", new Random().Next(0, 10000));
            var activityId = Guid.NewGuid().ToString();

            var firstSrv = new InvoicesServiceClient();
            firstSrv.BeginActivity(activityId);
            firstSrv.UpdateActivity(activityId, new InvoicesServiceType() { ReceivedDate = SqlDateTime.MinValue.Value, InvoiceId = invoiceId });
            firstSrv.EnableContinuation(activityId, invoiceId);
            firstSrv.EndActivity(activityId);

            var secondSrv = new InvoicesServiceClient();
            secondSrv.BeginActivity(invoiceId);
            secondSrv.UpdateActivity(invoiceId, new InvoicesServiceType() { Amount = 1001, ReceivedDate = DateTime.Now });
            secondSrv.EndActivity(invoiceId);
        }

    }
}
